
// Open MoneySpinner Suite v1
// An open source business management software system written in Java and MySQL
// Recommended IDE is NetBeans IDE 7.0.1
// Support Web Site: http://www.milliscript.com
//
// Copyright (C) 2014, Abiodun Aremu, Ibadan/NIGERIA.
// Open MoneySpinner Suite is distributed under the terms of the Apache License version 2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package openmoneyspinnersuite;

/**
 *
 * @author Abiodun Aremu
 */
import java.sql.*;
import javax.swing.*;

final class ConsentExpressDebitOrder extends javax.swing.JInternalFrame {

    Object[][] tableObject=new Object[][]{};
    Systems systems=new Systems();
    PreparedStatement statement;
    Thread consentExpressDebitOrderThread=new Thread();
    Thread consentExpressDebitOrderTitleThread=new Thread();
    /** Creates new form ViewCredit */
    /** Creates new form ViewCredit */
     ConsentExpressDebitOrder() {
        initComponents();

        setTitle("::. Consent Express Debit Order By User ("+OpenMSApp.EmployeeName+")");
        
        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            tableObject,
            new String [] {
                "Order Code", "Total Amount"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
            /* Execute refresh table thread */
            consentExpressDebitOrderThread=new Thread(new Runnable() {
                public void run() {
                    disableControls();
                    refreshTable();
                }
            });
            consentExpressDebitOrderTitleThread=new Thread(new Runnable() {
                public void run() {
                    while(consentExpressDebitOrderThread.isAlive())setProcessingTitle(consentExpressDebitOrderTitleThread);
                    System.out.println("consentExpressDebitOrderThread stopped runing.");
                    enableControls();
                }
            });
            consentExpressDebitOrderThread.start();
            consentExpressDebitOrderTitleThread.start();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jRefreshButton = new javax.swing.JButton();
        jCancelButton = new javax.swing.JButton();
        jSumTextField = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jDeleteButton = new javax.swing.JButton();
        jConsentButton = new javax.swing.JButton();

        setClosable(true);
        setIconifiable(true);
        setMaximizable(true);
        setResizable(true);
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(openmoneyspinnersuite.OpenMS_Finance_App.class).getContext().getResourceMap(ConsentExpressDebitOrder.class);
        setTitle(resourceMap.getString("Form.title")); // NOI18N
        setFrameIcon(resourceMap.getIcon("Form.frameIcon")); // NOI18N
        setName("Form"); // NOI18N
        setVisible(true);

        jScrollPane1.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
        jScrollPane1.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
        jScrollPane1.setName("jScrollPane1"); // NOI18N

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null}
            },
            new String [] {
                "Order Code", "Total Amount"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jTable1.setName("jTable1"); // NOI18N
        jTable1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                jTable1MousePressed(evt);
            }
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jTable1MouseReleased(evt);
            }
        });
        jTable1.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                jTable1PropertyChange(evt);
            }
        });
        jTable1.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTable1KeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTable1KeyReleased(evt);
            }
        });
        jTable1.addVetoableChangeListener(new java.beans.VetoableChangeListener() {
            public void vetoableChange(java.beans.PropertyChangeEvent evt)throws java.beans.PropertyVetoException {
                jTable1VetoableChange(evt);
            }
        });
        jScrollPane1.setViewportView(jTable1);
        jTable1.getColumnModel().getColumn(0).setPreferredWidth(10);
        jTable1.getColumnModel().getColumn(0).setHeaderValue(resourceMap.getString("jTable1.columnModel.title0")); // NOI18N
        jTable1.getColumnModel().getColumn(1).setHeaderValue(resourceMap.getString("jTable1.columnModel.title4")); // NOI18N

        jRefreshButton.setFont(resourceMap.getFont("jRefreshButton.font")); // NOI18N
        jRefreshButton.setIcon(resourceMap.getIcon("jRefreshButton.icon")); // NOI18N
        jRefreshButton.setText(resourceMap.getString("jRefreshButton.text")); // NOI18N
        jRefreshButton.setName("jRefreshButton"); // NOI18N
        jRefreshButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRefreshButtonActionPerformed(evt);
            }
        });

        jCancelButton.setFont(resourceMap.getFont("jCancelButton.font")); // NOI18N
        jCancelButton.setIcon(resourceMap.getIcon("jCancelButton.icon")); // NOI18N
        jCancelButton.setText(resourceMap.getString("jCancelButton.text")); // NOI18N
        jCancelButton.setName("jCancelButton"); // NOI18N
        jCancelButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCancelButtonActionPerformed(evt);
            }
        });

        jSumTextField.setEnabled(false);
        jSumTextField.setName("jSumTextField"); // NOI18N

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jDeleteButton.setText(resourceMap.getString("jDeleteButton.text")); // NOI18N
        jDeleteButton.setName("jDeleteButton"); // NOI18N
        jDeleteButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jDeleteButtonActionPerformed(evt);
            }
        });

        jConsentButton.setText(resourceMap.getString("jConsentButton.text")); // NOI18N
        jConsentButton.setName("jConsentButton"); // NOI18N
        jConsentButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jConsentButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 677, Short.MAX_VALUE)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSumTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 229, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 56, Short.MAX_VALUE)
                .addComponent(jConsentButton, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jDeleteButton, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jRefreshButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jCancelButton)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 267, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jCancelButton, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jRefreshButton, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jDeleteButton, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jConsentButton, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel1)
                        .addComponent(jSumTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jRefreshButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRefreshButtonActionPerformed
       
            /* Execute refresh table thread */
            consentExpressDebitOrderThread=new Thread(new Runnable() {
                public void run() {
                    disableControls();
                    refreshTable();
                }
            });
            consentExpressDebitOrderTitleThread=new Thread(new Runnable() {
                public void run() {
                    while(consentExpressDebitOrderThread.isAlive())setProcessingTitle(consentExpressDebitOrderTitleThread);
                    System.out.println("consentExpressDebitOrder stopped runing.");
                    enableControls();
                }
            });
            consentExpressDebitOrderThread.start();
            consentExpressDebitOrderTitleThread.start();
    }//GEN-LAST:event_jRefreshButtonActionPerformed

    private void setProcessingTitle(Thread thread)
    {
        try{
            setTitle("::. Consent Express Debit Order By User ("+OpenMSApp.EmployeeName+") - Processing Request");
            thread.sleep(500);
            setTitle("::. Consent Express Debit Order By User ("+OpenMSApp.EmployeeName+") - Processing Request.");
            thread.sleep(500);
            setTitle("::. Consent Express Debit Order By User ("+OpenMSApp.EmployeeName+") - Processing Request..");
            thread.sleep(500);
            setTitle("::. Consent Express Debit Order By User ("+OpenMSApp.EmployeeName+") - Processing Request...");
            thread.sleep(500);
        }catch(Exception e){System.out.println("Title thread error: "+e);}
    }
    private void jCancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCancelButtonActionPerformed
        
        if(consentExpressDebitOrderThread.isAlive())
        {
            try{
                consentExpressDebitOrderThread.stop();
                consentExpressDebitOrderThread.stop();
                System.out.println("Threads successfully stopped.");
            }catch(Exception e){System.out.println("Thread stopping error: "+e);}
            setTitle("::. Consent Express Debit Order By User ("+OpenMSApp.EmployeeName+")");
            enableControls();
        }
        else
        dispose();
    }//GEN-LAST:event_jCancelButtonActionPerformed

    private void jDeleteButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jDeleteButtonActionPerformed
       
            /* Execute refresh table thread */
            consentExpressDebitOrderThread=new Thread(new Runnable() {
                public void run() {
                    disableControls();
                    deleteButtonSelected();
                }
            });
            consentExpressDebitOrderTitleThread=new Thread(new Runnable() {
                public void run() {
                    while(consentExpressDebitOrderThread.isAlive())setProcessingTitle(consentExpressDebitOrderTitleThread);
                    System.out.println("consentExpressCreditOrderThread stopped runing.");
                    enableControls();
                }
            });
            consentExpressDebitOrderThread.start();
            consentExpressDebitOrderTitleThread.start();
    }//GEN-LAST:event_jDeleteButtonActionPerformed
    private void deleteButtonSelected()
    {
        if(jTable1.getSelectedRow()==-1)
        {
            javax.swing.JOptionPane.showMessageDialog(javax.swing.JOptionPane.getRootFrame(),"Please Select An Order !","Allocation ERROR !",javax.swing.JOptionPane.ERROR_MESSAGE);
        }
        else
        {
                    deleteSelectedOrderCode();
                    refreshTable();
        }
    }
    private void jTable1PropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_jTable1PropertyChange
        // TODO add your handling code here:
    }//GEN-LAST:event_jTable1PropertyChange

    private void jTable1VetoableChange(java.beans.PropertyChangeEvent evt)throws java.beans.PropertyVetoException {//GEN-FIRST:event_jTable1VetoableChange
        // TODO add your handling code here:
    }//GEN-LAST:event_jTable1VetoableChange

    private void jTable1MousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable1MousePressed
        // TODO add your handling code here:
        String firstValue="0";
        String secondValue="0";
        String sumValue="0";
            int x[]=jTable1.getSelectedRows();
            int count=jTable1.getSelectedRowCount();
            int y=0;
            if(count>0)
            {
                    while(y<count)
                    {
                        firstValue=sumValue;
                        try
                        {
                            secondValue=systems.converToRealMoneyFormat(jTable1.getValueAt(x[y],1).toString());
                        }
                        catch(Exception e)
                        {
                            secondValue="Er!M1C01K0";
                        }
                        sumValue=systems.getValue(OpenMSApp.Database_A, Connect.procInit+" prnAddMoney"+Connect.procInitStart+firstValue+" , "+secondValue+Connect.procInitEnd, "mSumValue");
                        System.out.println(firstValue+" "+secondValue+" "+sumValue);
                    y+=1;
                    if(count==y){break;}
                    }
                try
                {
                    jSumTextField.setText(systems.converToRealMoneyFormat(sumValue));
                }
                catch(Exception e)
                {
                    jSumTextField.setText("Er!M1C01K0");
                }
            }
    }//GEN-LAST:event_jTable1MousePressed

    private void jTable1MouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable1MouseReleased
        // TODO add your handling code here:
        String firstValue="0";
        String secondValue="0";
        String sumValue="0";
            int x[]=jTable1.getSelectedRows();
            int count=jTable1.getSelectedRowCount();
            int y=0;
            System.out.println("mr no of indices="+x.length+" no of rows selected="+count+" sel row"+jTable1.getSelectedRow());
            if(count>0)
            {
                    while(y<count)
                    {
                        firstValue=sumValue;
                        try
                        {
                            secondValue=systems.converToRealMoneyFormat(jTable1.getValueAt(x[y],1).toString());
                        }
                        catch(Exception e)
                        {
                            secondValue="Er!M1C01K0";
                        }
                        sumValue=systems.getValue(OpenMSApp.Database_A, Connect.procInit+" prnAddMoney"+Connect.procInitStart+firstValue+" , "+secondValue+Connect.procInitEnd, "mSumValue");
                        System.out.println(firstValue+" "+secondValue+" "+sumValue);
                    y+=1;
                    if(count==y){break;}
                    }
                try
                {
                    jSumTextField.setText(systems.converToRealMoneyFormat(sumValue));
                }
                catch(Exception e)
                {
                    jSumTextField.setText("Er!M1C01K0");
                }
            }
    }//GEN-LAST:event_jTable1MouseReleased

    private void jTable1KeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTable1KeyPressed
        // TODO add your handling code here:
        String firstValue="0";
        String secondValue="0";
        String sumValue="0";
            int x[]=jTable1.getSelectedRows();
            int count=jTable1.getSelectedRowCount();
            int y=0;
            System.out.println("kp no of indices="+x.length+" no of rows selected="+count+" sel row"+jTable1.getSelectedRow());
            if(count>0)
            {
                    while(y<count)
                    {
                        firstValue=sumValue;
                        try
                        {
                            secondValue=systems.converToRealMoneyFormat(jTable1.getValueAt(x[y],1).toString());
                        }
                        catch(Exception e)
                        {
                            secondValue="Er!M1C01K0";
                        }
                        sumValue=systems.getValue(OpenMSApp.Database_A, Connect.procInit+" prnAddMoney"+Connect.procInitStart+firstValue+" , "+secondValue+Connect.procInitEnd, "mSumValue");
                        System.out.println(firstValue+" "+secondValue+" "+sumValue);
                    y+=1;
                    if(count==y){break;}
                    }
                try
                {
                    jSumTextField.setText(systems.converToRealMoneyFormat(sumValue));
                }
                catch(Exception e)
                {
                    jSumTextField.setText("Er!M1C01K0");
                }
            }
    }//GEN-LAST:event_jTable1KeyPressed

    private void jTable1KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTable1KeyReleased
        // TODO add your handling code here:
        String firstValue="0";
        String secondValue="0";
        String sumValue="0";
            int x[]=jTable1.getSelectedRows();
            int count=jTable1.getSelectedRowCount();
            int y=0;
            System.out.println("kr no of indices="+x.length+" no of rows selected="+count+" sel row"+jTable1.getSelectedRow());
            if(count>0)
            {
                    while(y<count)
                    {
                        firstValue=sumValue;
                        try
                        {
                            secondValue=systems.converToRealMoneyFormat(jTable1.getValueAt(x[y],1).toString());
                        }
                        catch(Exception e)
                        {
                            secondValue="Er!M1C01K0";
                        }
                        sumValue=systems.getValue(OpenMSApp.Database_A, Connect.procInit+" prnAddMoney"+Connect.procInitStart+firstValue+" , "+secondValue+Connect.procInitEnd, "mSumValue");
                        System.out.println(firstValue+" "+secondValue+" "+sumValue);
                    y+=1;
                    if(count==y){break;}
                    }
                try
                {
                    jSumTextField.setText(systems.converToRealMoneyFormat(sumValue));
                }
                catch(Exception e)
                {
                    jSumTextField.setText("Er!M1C01K0");
                }
            }
    }//GEN-LAST:event_jTable1KeyReleased

    private void jConsentButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jConsentButtonActionPerformed
        
            /* Execute refresh table thread */
            consentExpressDebitOrderThread=new Thread(new Runnable() {
                public void run() {
                    disableControls();
                    consentButtonSelected();
                }
            });
            consentExpressDebitOrderTitleThread=new Thread(new Runnable() {
                public void run() {
                    while(consentExpressDebitOrderThread.isAlive())setProcessingTitle(consentExpressDebitOrderTitleThread);
                    System.out.println("consentExpressDebitOrderThread stopped runing.");
                    enableControls();
                }
            });
            consentExpressDebitOrderThread.start();
            consentExpressDebitOrderTitleThread.start();
    }//GEN-LAST:event_jConsentButtonActionPerformed
    private void consentButtonSelected()
    {
        if(jTable1.getSelectedRow()==-1)
        {
            javax.swing.JOptionPane.showMessageDialog(javax.swing.JOptionPane.getRootFrame(),"Please Select An Order !","Allocation ERROR !",javax.swing.JOptionPane.ERROR_MESSAGE);
        }
        if(selectedAccountActive()==false)
        {
            JOptionPane.showMessageDialog(JOptionPane.getRootFrame()," SELECTED ACCOUNT IS FROZEN ! \n SEE YOUR ACCOUNT ADMINISTRATOR.","ERROR !",JOptionPane.ERROR_MESSAGE);
            return;
        }
        if(selectedAccountDebitable()==false)
        {
                JOptionPane.showMessageDialog(JOptionPane.getRootFrame()," INSUFFICIENT FUND IN THE SELECTED ACCOUNT \n  FOR THIS TRANSACTION !","ERROR !",JOptionPane.ERROR_MESSAGE);
                return;
        }
        consentSelectedOrderCode();
        refreshTable();
    }
    void consentSelectedOrderCode()
    {
        int x[]=jTable1.getSelectedRows();
        int count=jTable1.getSelectedRowCount();
        int y=0;
        System.out.println("const no of indices="+x.length+" no of rows selected="+count+" sel row"+jTable1.getSelectedRow());
        if(count>0)
        {
            while(y<count)
            {
                String status=systems.getValue(OpenMSApp.Database_A, "Select * from debitOrder where cDebitOrderCode='"+jTable1.getValueAt(x[y],0).toString()+"'", "cStatus");
                if(status.equalsIgnoreCase("approved")||status.equalsIgnoreCase("deleted")){
                refreshTable();
                return;
                }
                y+=1;
                if(count==y){break;}
            }
            y=0;
            //Connect.createMSSQLConnection();
            Connect.changeDB(OpenMSApp.Database_A);
            System.out.println("order code="+jTable1.getValueAt(x[y],0).toString()+"first indices="+x[y]);

            while(y<count)
            {
                    String refID=systems.getValue(OpenMSApp.Database_A, "Select * from Debitorder where cDebitOrderCode='"+jTable1.getValueAt(x[y],0).toString()+"'", "cRefID");

                statement=Connect.createStatement(Connect.procInit+"  prnUpdDebitOrderOnConsent"+Connect.procInitStart+"?,?"+Connect.procInitEnd);
                try
                {
                    statement.setString(1,refID);
                    statement.setString(2,OpenMSApp.LoginCode);
                }
                catch(Exception e)
                {
                    System.out.println("ConsentExpressDebitOrder.consentButtonActionPerformed gave error! "+e);
                }
                Connect.executeUpdateStatement(statement);
                statement=Connect.createStatement(Connect.procInit+"  prnUpdCreditOrderOnConsent"+Connect.procInitStart+"?,?"+Connect.procInitEnd);
                try
                {
                    statement.setString(1,refID);
                    statement.setString(2,OpenMSApp.LoginCode);
                }
                catch(Exception e)
                {
                    System.out.println("ConsentExpressDebitOrder.consentButtonActionPerformed gave error! "+e);
                }
                Connect.executeUpdateStatement(statement);
                y+=1;
                if(count==y){break;}
            }

            Connect.alert="Y";
            Connect.closeConnection();
        }        
    }
     void deleteSelectedOrderCode()
    {
        int x[]=jTable1.getSelectedRows();
        int count=jTable1.getSelectedRowCount();
        int y=0;
        System.out.println("const no of indices="+x.length+" no of rows selected="+count+" sel row"+jTable1.getSelectedRow());
        if(count>0)
        {
            while(y<count)
            {
                String status=systems.getValue(OpenMSApp.Database_A, "Select * from debitOrder where cDebitOrderCode='"+jTable1.getValueAt(x[y],0).toString()+"'", "cStatus");
                if(status.equalsIgnoreCase("approved")||status.equalsIgnoreCase("deleted")){
                refreshTable();
                return;
                }
                y+=1;
                if(count==y){break;}
            }
            y=0;
                    String refID=systems.getValue(OpenMSApp.Database_A, "Select * from Debitorder where cDebitOrderCode='"+jTable1.getValueAt(x[y],0).toString()+"'", "cRefID");

            //Connect.createMSSQLConnection();
            Connect.changeDB(OpenMSApp.Database_A);
            System.out.println("order code="+jTable1.getValueAt(x[y],0).toString()+"first indices="+x[y]);

            while(y<count)
            {
                statement=Connect.createStatement(Connect.procInit+"  prnDeleteDebitOrder"+Connect.procInitStart+"?,?"+Connect.procInitEnd);
                try
                {
                    statement.setString(1,refID);
                    statement.setString(2,OpenMSApp.LoginCode);
                }
                catch(Exception e)
                {
                    System.out.println("ConsentExpressDebitOrder.deleteButtonActionPerformed gave error! "+e);
                }
                Connect.executeUpdateStatement(statement);
                statement=Connect.createStatement(Connect.procInit+"  prnDeleteCreditOrder"+Connect.procInitStart+"?,?"+Connect.procInitEnd);
                try
                {
                    statement.setString(1,refID);
                    statement.setString(2,OpenMSApp.LoginCode);
                }
                catch(Exception e)
                {
                    System.out.println("ConsentExpressDebitOrder.deleteButtonActionPerformed gave error! "+e);
                }
                Connect.executeUpdateStatement(statement);
                y+=1;
                if(count==y){break;}
            }

            Connect.alert="Y";
            Connect.closeConnection();
        }        
    }
     private void enableControls()
     {
         jConsentButton.setEnabled(true);
         jDeleteButton.setEnabled(true);
         jRefreshButton.setEnabled(true);
         setTitle("::. Consent Express Debit Order By User ("+OpenMSApp.EmployeeName+")");
     }
     private void disableControls()
     {
         jConsentButton.setEnabled(false);
         jDeleteButton.setEnabled(false);
         jRefreshButton.setEnabled(false);
         setTitle("::. Consent Express Debit Order By User ("+OpenMSApp.EmployeeName+")");
     }
     boolean selectedAccountActive()
    {
        boolean accountActive=true;
    
        int x[]=jTable1.getSelectedRows();
        int count=jTable1.getSelectedRowCount();
        int y=0;
        System.out.println("isActAtv no of indices="+x.length+" no of rows selected="+count+" sel row"+jTable1.getSelectedRow());
        if(count>0)
        {        
            while(y<count)
            {
                String accountCode=systems.getValue(OpenMSApp.Database_A, "Select * from DebitOrder where cDebitOrderCode='"+jTable1.getValueAt(x[y],0).toString()+"'", "cAccountCode");
                String accountStatus=systems.getValue(OpenMSApp.Database_A, "Select * from Account where cAccountCode='"+accountCode+"'", "cStatus");
                if(accountStatus.equalsIgnoreCase("Frozen"))
                {
                    accountActive=false;
                }
                y+=1;
                if(count==y){break;}
            }
        }
        return accountActive;
    }
     boolean selectedAccountDebitable()
    {
        boolean accountDebitable=true;
        
        int x[]=jTable1.getSelectedRows();
        int count=jTable1.getSelectedRowCount();
        int y=0;
        System.out.println("isActDeb no of indices="+x.length+" no of rows selected="+count+" sel row"+jTable1.getSelectedRow());
        if(count>0)
        {        
            while(y<count)
            {
                String accountCode=systems.getValue(OpenMSApp.Database_A, "Select * from DebitOrder where cDebitOrderCode='"+jTable1.getValueAt(x[y],0).toString()+"'", "cAccountCode");
                String totalAmount=systems.getValue(OpenMSApp.Database_A, "Select * from DebitOrder where cDebitOrderCode='"+jTable1.getValueAt(x[y],0).toString()+"'", "mTotalAmount");
                String accountBalance=systems.getValue(OpenMSApp.Database_A, "Select * from Account where cAccountCode='"+accountCode+"'", "mAmount");
                String newAccountBalance=systems.getValue(OpenMSApp.Database_A, Connect.procInit+" prnSubtractMoney"+Connect.procInitStart+""+accountBalance+","+totalAmount+Connect.procInitEnd, "mSumValue");
                try
                {
                    systems.converToRealMoneyFormat(newAccountBalance);
                }
                catch(Exception e)
                {
                    accountDebitable=false;
                }
                y+=1;
                if(count==y){break;}
            }
        }    
        return accountDebitable;
    }
     void refreshTable()
    {
        String[] departmentCode=systems.getTableDataArrayNum(OpenMSApp.Database_A,"vwPendingDebitOrder",1);
        String[] departmentName=systems.getTableDataArrayNum(OpenMSApp.Database_A,"vwPendingDebitOrder",3);

        int x=0;
        int y=departmentCode.length;

        tableObject=new Object[y][2];

        while(x<y)
        {
            tableObject[x][0]=departmentCode[x].trim();
            tableObject[x][1]=departmentName[x].trim();
            x+=1;
            if(x==y){break;}
       }

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            tableObject,
            new String [] {
                "Order Code", "Total Amount"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });


        String firstValue="0";
        String secondValue="0";
        String sumValue="0";

            int a=tableObject.length;
            int b=0;
            while(b<a)
            {
                if(jTable1.getValueAt(b,1)!=null)
                {
                    firstValue=sumValue;
                    try
                    {
                        secondValue=systems.converToRealMoneyFormat(jTable1.getValueAt(b,1).toString());
                    }
                    catch(Exception e)
                    {
                        secondValue="Er!M1C01K0";
                    }
                    sumValue=systems.getValue(OpenMSApp.Database_A, Connect.procInit+" prnAddMoney"+Connect.procInitStart+firstValue+" , "+secondValue+Connect.procInitEnd, "mSumValue");
                    System.out.println(firstValue+" "+secondValue+" "+sumValue);
                }
                b+=1;
                if(b==a){break;}
            }
        try
        {
            jSumTextField.setText(systems.converToRealMoneyFormat(sumValue));
        }
        catch(Exception e)
        {
            jSumTextField.setText("Er!M1C01K0");
        }

    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jCancelButton;
    private javax.swing.JButton jConsentButton;
    private javax.swing.JButton jDeleteButton;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JButton jRefreshButton;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextField jSumTextField;
    private javax.swing.JTable jTable1;
    // End of variables declaration//GEN-END:variables

}
